package MineGod;

import java.util.ArrayList;


public class BlockWaterGenerator extends BlockGenerator{
		
	private int maxBigness = 6;
	private int minBigness = 3;
	
	
	public BlockWaterGenerator(){
		super(BlockType.water);
		minVeinLength = 60;
		maxVeinLength = 100;
	}

	public Block provideBlock(){
		return new BlockWater();
	}
	
	public ArrayList<int[]> generateVein(Chunk chunk) {
		int bigness = Chunk.rand.nextInt(maxBigness - minBigness + 1) + minBigness;
		int i = Chunk.rand.nextInt(chunk.blocks.length);
		int j = Chunk.rand.nextInt(chunk.blocks[i].length);
		
		//chunk.blocks[i][j] = provideBlock();
		ArrayList<int[]> offRightOrLeft = new ArrayList<int[]>();
		ArrayList<int[]> valid = new ArrayList<int[]>();
		valid.add(new int[] {i, j});
		//Now create the vein
		for (int k = 0; k < bigness; k++){
			int tempHeight = Chunk.rand.nextInt(2) + bigness;
			int tempLevel = Chunk.rand.nextInt(2)-1;
			for(int y = 0; y < tempHeight; y++) {
				int checkX = i + k;
				int checkY = j + y + tempLevel;
				if(!(checkX < 0 || checkX >= chunk.blocks.length || checkY < 0 || checkY >= Chunk.CHUNK_HEIGHT) && !(chunk.blocks[checkX][checkY].type == type)){
					valid.add(new int[] {checkX,checkY});
				}
				else if ((checkX < 0 || checkX >= chunk.blocks.length) && !(checkY < 0 || checkY >= Chunk.CHUNK_HEIGHT)){
					valid.add(new int[] {checkX,checkY});
				}
			}
			
			if (valid.size() == 0){
				break;
			}
		}
		for(int[] array: valid){
			i = array[0];
			j = array[1];
			if(!(j < 0 || j >= Chunk.CHUNK_HEIGHT)){
				if(i >= chunk.blocks.length || i < 0) {
					offRightOrLeft.add(new int[] {i,j});
				}
				else{
					if (chunk.blocks[i][j].isSolid){
						chunk.blocks[i][j] = provideBlock();
					}
				}
			}
		}
		return offRightOrLeft;
	}
	
}
